package com.adcc.ags.gms.mq.controller;

import com.adcc.ags.gms.core.util.Constant;
import com.adcc.ags.gms.core.util.LogFactory;
import com.adcc.ags.gms.core.vo.ResultState;
import com.adcc.ags.gms.core.vo.ResultVO;
import com.adcc.ags.gms.mq.service.QueueService;
import com.adcc.ags.gms.mq.vo.QueueVO;
import com.google.common.base.Optional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 系统队列控制层
 */
@Controller
@RequestMapping(value = "/SysQueue",produces = MediaType.APPLICATION_JSON_VALUE)
public class SysQueueController {

    @Autowired
    private LogFactory log;

    @Autowired
    private QueueService service;

    /**
     * 查询所有系统队列
     * @return
     */
    @RequestMapping(value = "/findAllSysQueue",method = RequestMethod.GET)
    public @ResponseBody ResultVO findAllSysQueue(){
        ResultVO resultVO = new ResultVO();
        try{
            Optional<List<QueueVO>> optional = service.findAllSysQueue();
            if(optional.isPresent()){
                List<QueueVO> list = optional.get();
                resultVO.getData().put("queueVO",list);
            }else{
                resultVO.setCode(-1);
                resultVO.setState(ResultState.FAILURE);
                resultVO.setReason(Constant.GMS_PCF_ERROR);
            }
        }catch (Exception ex){
            log.error(SysQueueController.class, "findAllSysQueue() error", ex);
            resultVO.setCode(-1);
            resultVO.setState(ResultState.FAILURE);
            resultVO.setReason(Constant.GMS_SERVER_ERROR);
        }
        return resultVO;
    }
}
